package com.taomu.app.zongchouhuli.utils;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Matrix;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.taomu.app.zongchouhuli.R;
import com.taomu.app.zongchouhuli.moudle.login.activity.LoginActivity;

public class TokenDialog {

    private Context mContext;

    private static TokenDialog instance;

    private Dialog dialog;

    private TokenDialog(Context mContext){
        this.mContext = mContext;
    }

    public static TokenDialog getInsence(Context mContext){
        if(instance==null){
            synchronized(TokenDialog.class){
                if(instance==null){
                    instance = new TokenDialog(mContext);
                }
            }
        }
        return instance;
    }

    public void show(){
        if(dialog == null){
            View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_token_error, null);
            final TextView login = view.findViewById(R.id.login_tv);
            login.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    StorageHelper.removeToken();
                    StorageHelper.removeUid();
                    mContext.startActivity(new Intent(mContext,LoginActivity.class));
                    if(dialog != null){
                        dialog.dismiss();
                    }
                }
            });
            dialog = new Dialog(mContext);
            dialog.setCanceledOnTouchOutside(false);
            dialog.setContentView(view);
            dialog.show();
        }else{
            if(!dialog.isShowing()){
                dialog.show();
            }
        }
    }
}
